Ext.define('Ext.ux.ckeditor', {
    extend: 'Ext.form.field.TextArea',
    alias: 'widget.ckeditor',
    initComponent: function () {
        this.callParent(arguments);

        this.on('afterrender', function () {
            Ext.apply(this.CKConfig, {
                height: this.getHeight()

            });
            console.log(this.CKConfig);
            this.editor = CKEDITOR.replace(this.inputEl.id, this.CKConfig);
            this.editorId = this.editor.id;
        }, this);

    },

    onRender: function (ct, position) {
        if (!this.el) {

            this.defaultAutoCreate = {
                tag: 'textarea',
                autocomplete: 'off'
            };
        }
        this.callParent(arguments);


    },
    getValue: function () {
        if (this.editor) {
            this.editor.getData();
        }
    },
    setValue: function (value) {
        this.callParent(arguments);
        if (this.editor) {
            this.editor.setData(value);
        }
    },
    getRawValue: function () {
        if (this.editor) {
            return this.editor.getData();
        } else {
            return '';
        }
    }

});

CKEDITOR.on('instanceReady', function(e) {
    var o = Ext.ComponentQuery.query('ckeditor[editorId="' + e.editor.id + '"]'),
comp = o[0];
    e.editor.resize((comp.getWidth() - 20), comp.getHeight())
    comp.on('resize', function(c, adjWidth, adjHeight) {
        c.editor.resize((adjWidth - 20), adjHeight)
    })

});